//
//  YGKJMessageVC.m
//  新项目
//
//  Created by 刘耀宗 on 2017/4/3.
//  Copyright © 2017年 刘耀宗. All rights reserved.
//

#import "YGKJMessageVC.h"
#import "YYYCell.h"
#import "WBPopMenuModel.h"
#import "WBPopMenuSingleton.h"
@interface YGKJMessageVC ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray *NumArr1;
@property (nonatomic, strong) NSArray *NumArr2;
@property (nonatomic, strong) NSArray *NumArr3;
@property (nonatomic, strong) NSArray *NumArr4;
@property (nonatomic, strong) NSMutableArray *textArr;

@end

@implementation YGKJMessageVC
- (NSArray *) titles {
    return @[@"双色球",
             @"重庆时时彩",
             @"超级大乐透",
             @"PK10",
             @"PC蛋蛋",
             @"排列三",
             @"排列5",
             @"7乐彩",
             @"新快5"];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"摇一摇";
    self.NumArr1=@[@"万",@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
    self.NumArr2=@[@"千",@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
    self.NumArr3=@[@"百",@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
    self.NumArr4=@[@"个",@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
    self.textArr=[NSMutableArray arrayWithArray:@[@1,@1,@1,@1]];
  ;
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    self.tableView.separatorStyle=0;
    

    [self.tableView registerClass:[YYYCell class] forCellReuseIdentifier:@"YYYCell"];
    [self.tableView reloadData];
    
    UIBarButtonItem *rightItem=[[UIBarButtonItem alloc] initWithTitle:@"彩种" style:UIBarButtonItemStylePlain target:self action:@selector(clickForChoose)];
    self.navigationItem.rightBarButtonItem=rightItem;
    
    
    // Do any additional setup after loading the view from its nib.
}
//选择彩种
-(void)clickForChoose
{ NSMutableArray *obj = [NSMutableArray array];
    
    for (NSInteger i = 0; i < [self titles].count; i++) {
        
        WBPopMenuModel * info = [WBPopMenuModel new];
        //        info.image = [self images][i];
        info.title = [self titles][i];
        [obj addObject:info];
    }

    [[WBPopMenuSingleton shareManager]showPopMenuSelecteWithFrame:120
                                                             item:obj
                                                           action:^(NSInteger index) {
                                                               for (int i = 0; i < 4; ++i) {
                                                                   NSInteger num=[self getRandomNumber:1 to:10];
                                                                   self.textArr[i]=[NSString stringWithFormat:@"%ld",num];
                                                               }
                                                               [self.tableView reloadData];
                                                               
                                                           }];
    
    
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;

}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YYYCell *cell=[YYYCell CellWithTable:tableView];
    if (indexPath.section==0) {
        cell.arr=self.NumArr1;
        cell.num=[self.textArr[0] integerValue];
        
    }
    if (indexPath.section==1) {
        cell.arr=self.NumArr2;
            cell.num=[self.textArr[1] integerValue];
    }
    if (indexPath.section==2) {
        cell.arr=self.NumArr3;
            cell.num=[self.textArr[2] integerValue];
    }
    if (indexPath.section==3) {
        cell.arr=self.NumArr4;
            cell.num=[self.textArr[3] integerValue];
    }
    
    return cell;
    

}
-(int)getRandomNumber:(int)from to:(int)to
{
    return (int)(from + (arc4random() % (to-  from + 1)));
}

/**
 开始摇一摇
 */
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    NSLog(@"开始摇一摇");
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSLog(@"结束摇一摇");
    for (int i = 0; i < 4; ++i) {
        NSInteger num=[self getRandomNumber:1 to:10];
        self.textArr[i]=[NSString stringWithFormat:@"%ld",num];
    }
    [self.tableView reloadData];
    
    
}
- (IBAction)clickForYyy:(id)sender {
    for (int i = 0; i < 4; ++i) {
        NSInteger num=[self getRandomNumber:1 to:10];
        self.textArr[i]=[NSString stringWithFormat:@"%ld",num];
    }
    [self.tableView reloadData];
}


- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    NSLog(@"取消摇一摇");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
